<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Harbor Docker 入门教程</title>
    <meta name="description" content="Harbor 是 VMware 公司开源了企业级 Registry 项目, 其的目标是帮助用户迅速搭建一个企业级的 Docker registry 服务。">
    <meta name="keywords" content="docker,containers,tutorial">
    <link rel="stylesheet" type="text/css" href="css/main.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="css/tocbot.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="css/media.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="css/sidebar.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="css/copy.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="css/demo-preview.css?v=1.29.0">
    <link rel="icon" href="img/logo.svg" type="image/x-icon">
    <script src="js/copy.js?v=1.29.0"></script>
    <script src="js/dark-mode.js?v=1.29.0"></script>
    <script src="js/markdown-style.js?v=1.29.0"></script>
  </head>
  <body id="idoctotop"><a href="#idoctotop" class="gototop">top</a>
    <header class="header">
      <article class="inner warpper"><a class="logo" href="index.html"><svg viewBox="0 0 1280 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
            <path d="M699.88718 472.6h-132.2v-118.8h132.2v118.8z m0-408.6h-132.2v121.4h132.2V64z m156.4 289.6H724.08718v118.8h132.2v-118.8z m-312.6-144.2h-132.2v120.2h132.2v-120.2z m156.2 0h-132.2v120.2h132.2v-120.2z m553.6 200c-28.8-19.4-95.2-26.4-146.2-16.8-6.6-48-33.4-89.8-82.2-127.4l-28-18.6-18.6 28c-36.8 55.6-46.8 147.2-7.4 207.6-17.4 9.4-51.6 22.2-96.8 21.4H4.88718c-17.4 101.6 11.6 233.6 88 324.2 74.2 87.8 185.4 132.4 330.8 132.4 314.8 0 547.8-145 656.8-408.4 42.8 0.8 135.2 0.2 182.6-90.4 3-5 13.2-26.4 17-34.2l-26.6-17.8z m-1022.2-55.8h-132v118.8h132.2v-118.8z m156.2 0h-132.2v118.8h132.2v-118.8z m156.2 0h-132.2v118.8h132.2v-118.8z m-156.2-144.2h-132.2v120.2h132.2v-120.2z" fill="#0187D1"></path>
          </svg>
<span class="title">Docker 入门教程</span></a>
        <div class="content">
          <ul class="menu">
            <li><a href="index.html" target="" class="">Home</a></li>
            <li><a href="https://wangchujiang.com/#/sponsor" target="__blank" class="">Sponsor</a></li>
          </ul><a href="https://github.com/jaywcjlove/docker-tutorial" target="_blank" rel="noopener noreferrer" title="Github" name="Github" class="github"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
              <path d="M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22"></path>
            </svg></a>
          <dark-mode permanent=""></dark-mode>
        </div>
      </article>
    </header>
    <div class="warpper-content warpper sidebar">
      <div class="sidebar-border">
        <aside class="sidebar" role="navigation">
          <div>
            <a href="index.html" class="">入门</a>
            <label>实践</label>
            <a href="docker-compose.html" class="">Docker Compose</a>
            <a href="elasticsearch.html" class="">ElasticSearch 搜索服务器</a>
            <a href="gitlab/index.html" class="">Gitlab 代码仓库管理系统</a>
            <a href="harbor.html" class="active">Harbor</a>
            <a href="mattermost.html" class="">Mattermost 聊天工具</a>
            <a href="mysql.html" class="">MySQL 数据库</a>
            <a href="nginx.html" class="">Nginx Web 服务器</a>
            <a href="nps/index.html" class="">NPS 内网穿透</a>
            <a href="portainer.html" class="">Portainer Docker 管理</a>
            <a href="postgres.html" class="">PostgreSQL 数据库</a>
            <a href="penpot.html" class="">Penpot 设计和原型</a>
            <a href="navidrome.html" class="">Navidrome 音乐服务器</a>
            <a href="rancher.html" class="">Rancher 容器管理平台</a>
            <a href="redis.html" class="">Redis 数据库</a>
            <a href="rocket.chat/index.html" class="">Rocket.Chat 聊天工具</a>
            <a href="seaweedfs/index.html" class="">SeaweedFS 文件系统</a>
            <a href="sourcegraph/index.html" class="">Sourcegraph 代码搜索引擎</a>
          </div>
        </aside>
      </div>
      <markdown-style theme-auto-switch-disabled="">
        <h1 id="harbor"><a aria-hidden="true" tabindex="-1" href="#harbor" class="anchor"><span class="icon icon-link"></span></a>Harbor</h1>
        <p><a href="https://goharbor.io/">Harbor</a> 是 <code>VMware</code> 公司开源了企业级 <code>Registry</code> 项目, 其的目标是帮助用户迅速搭建一个企业级的 <code>Docker registry</code> 服务。</p>
        <p>由于 Harbor 是基于 Docker Registry V2 版本，所以 docker 版本必须 <code>>=1.10.0</code> <a href="https://docs.docker.com/compose/install/#prerequisites">docker-compose</a> <code>>=1.6.0</code></p>
        <p>Github: <a href="https://github.com/goharbor/harbor">goharbor/harbor</a>，官方<a href="https://demo.goharbor.io/">预览示例</a></p>
        <p>对硬件需求</p>
        <blockquote>
          <p>CPU => 最小 2CPU/4CPU(首选)<br>Mem => 最小 4GB/8GB(首选)<br>Disk => 最小 40GB/160G(首选)</p>
        </blockquote>
        <h2 id="下载安装包"><a aria-hidden="true" tabindex="-1" href="#下载安装包" class="anchor"><span class="icon icon-link"></span></a>下载安装包</h2>
        <p>CentOS中通过 <a href="https://docs.docker.com/compose/install/#prerequisites">docker-compose</a> 安装部署。</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token comment"># 下载最新版 `Docker Compose`</span>
</span><span class="code-line line-number" line="2"><span class="token function">sudo</span> <span class="token function">curl</span> <span class="token parameter variable">-L</span> <span class="token string">"https://github.com/docker/compose/releases/download/1.22.0/docker-compose-<span class="token variable"><span class="token variable">$(</span><span class="token function">uname</span> <span class="token parameter variable">-s</span><span class="token variable">)</span></span>-<span class="token variable"><span class="token variable">$(</span><span class="token function">uname</span> <span class="token parameter variable">-m</span><span class="token variable">)</span></span>"</span> <span class="token parameter variable">-o</span> /usr/local/bin/docker-compose
</span><span class="code-line line-number" line="3"><span class="token comment"># 对二进制文件应用可执行权限：</span>
</span><span class="code-line line-number" line="4"><span class="token function">sudo</span> <span class="token function">chmod</span> +x /usr/local/bin/docker-compose
</span><span class="code-line line-number" line="5"><span class="token comment"># 测试是否安装成功</span>
</span><span class="code-line line-number" line="6"><span class="token function">docker-compose</span> <span class="token parameter variable">--version</span>
</span><span class="code-line line-number" line="7"><span class="token comment"># docker-compose version 1.22.0, build f46880fe</span>
</span></code><input type="hidden" value="# 下载最新版 &#x60;Docker Compose&#x60;
sudo curl -L &#x22;https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)&#x22; -o /usr/local/bin/docker-compose
# 对二进制文件应用可执行权限：
sudo chmod +x /usr/local/bin/docker-compose
# 测试是否安装成功
docker-compose --version
# docker-compose version 1.22.0, build f46880fe
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>可以从<a href="https://github.com/goharbor/harbor/releases">发布页面</a>下载安装程序的二进制文件，选择在线或离线安装程序，使用tar命令解压缩包，天朝人民下面这种方式安装可能要翻墙，推荐这种方式，因为上面也不见得能下载下来。</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token comment"># 下载离线安装包</span>
</span><span class="code-line line-number" line="2"><span class="token function">wget</span> https://storage.googleapis.com/harbor-releases/release-1.6.0/harbor-offline-installer-v1.6.0.tgz
</span><span class="code-line line-number" line="3"><span class="token comment"># 解压缩包</span>
</span><span class="code-line line-number" line="4"><span class="token function">tar</span> xvf harbor-offline-installer-v1.6.0.tgz
</span></code><input type="hidden" value="# 下载离线安装包
wget https://storage.googleapis.com/harbor-releases/release-1.6.0/harbor-offline-installer-v1.6.0.tgz
# 解压缩包
tar xvf harbor-offline-installer-v1.6.0.tgz
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <h2 id="修改配置"><a aria-hidden="true" tabindex="-1" href="#修改配置" class="anchor"><span class="icon icon-link"></span></a>修改配置</h2>
        <p>进去 <code>vim harbor/harbor.cfg</code> 修改文件相关配置。</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token comment"># hostname 设置访问地址，支持IP，域名，主机名，禁止设置127.0.0.1</span>
</span><span class="code-line line-number" line="2"><span class="token function">hostname</span> <span class="token operator">=</span> reg.mydomain.com
</span><span class="code-line line-number" line="3"><span class="token comment"># 访问协议，可设置 http,https</span>
</span><span class="code-line line-number" line="4">ui_url_protocol <span class="token operator">=</span> http
</span><span class="code-line line-number" line="5">
</span><span class="code-line line-number" line="6"><span class="token comment"># 邮件通知, 配置邮件通知。</span>
</span><span class="code-line line-number" line="7">email_identity <span class="token operator">=</span>
</span><span class="code-line line-number" line="8">email_server <span class="token operator">=</span> smtp.mydomain.com
</span><span class="code-line line-number" line="9">email_server_port <span class="token operator">=</span> <span class="token number">25</span>
</span><span class="code-line line-number" line="10">email_username <span class="token operator">=</span> sample_admin@mydomain.com
</span><span class="code-line line-number" line="11">email_password <span class="token operator">=</span> abc
</span><span class="code-line line-number" line="12">email_from <span class="token operator">=</span> admin <span class="token operator">&#x3C;</span>sample_admin@mydomain.com<span class="token operator">></span>
</span><span class="code-line line-number" line="13">email_ssl <span class="token operator">=</span> <span class="token boolean">false</span>
</span><span class="code-line line-number" line="14">email_insecure <span class="token operator">=</span> <span class="token boolean">false</span>
</span><span class="code-line line-number" line="15">
</span><span class="code-line line-number" line="16"><span class="token comment"># harbor WEB UI登陆使用的密码</span>
</span><span class="code-line line-number" line="17">harbor_admin_password <span class="token operator">=</span> Harbor12345
</span><span class="code-line line-number" line="18">
</span><span class="code-line line-number" line="19"><span class="token comment"># 认证方式，这里支持多种认证方式，默认是 db_auth ，既mysql数据库存储认证。</span>
</span><span class="code-line line-number" line="20"><span class="token comment"># 这里还支持 ldap 以及 本地文件存储方式。</span>
</span><span class="code-line line-number" line="21">auth_mode <span class="token operator">=</span> db_auth
</span><span class="code-line line-number" line="22"><span class="token comment"># ldap 服务器访问地址。</span>
</span><span class="code-line line-number" line="23">ldap_url <span class="token operator">=</span> ldaps://ldap.mydomain.com
</span><span class="code-line line-number" line="24">ldap_basedn <span class="token operator">=</span> <span class="token assign-left variable">uid</span><span class="token operator">=</span>%s,ou<span class="token operator">=</span>people,dc<span class="token operator">=</span>mydomain,dc<span class="token operator">=</span>com
</span><span class="code-line line-number" line="25">
</span><span class="code-line line-number" line="26"><span class="token comment"># mysql root 账户的 密码</span>
</span><span class="code-line line-number" line="27">db_password <span class="token operator">=</span> root123
</span><span class="code-line line-number" line="28">self_registration <span class="token operator">=</span> on
</span><span class="code-line line-number" line="29">use_compressed_js <span class="token operator">=</span> on
</span><span class="code-line line-number" line="30">max_job_workers <span class="token operator">=</span> <span class="token number">3</span> 
</span><span class="code-line line-number" line="31">verify_remote_cert <span class="token operator">=</span> on
</span><span class="code-line line-number" line="32">customize_crt <span class="token operator">=</span> on
</span></code><input type="hidden" value="# hostname 设置访问地址，支持IP，域名，主机名，禁止设置127.0.0.1
hostname = reg.mydomain.com
# 访问协议，可设置 http,https
ui_url_protocol = http

# 邮件通知, 配置邮件通知。
email_identity =
email_server = smtp.mydomain.com
email_server_port = 25
email_username = sample_admin@mydomain.com
email_password = abc
email_from = admin <sample_admin@mydomain.com>
email_ssl = false
email_insecure = false

# harbor WEB UI登陆使用的密码
harbor_admin_password = Harbor12345

# 认证方式，这里支持多种认证方式，默认是 db_auth ，既mysql数据库存储认证。
# 这里还支持 ldap 以及 本地文件存储方式。
auth_mode = db_auth
# ldap 服务器访问地址。
ldap_url = ldaps://ldap.mydomain.com
ldap_basedn = uid=%s,ou=people,dc=mydomain,dc=com

# mysql root 账户的 密码
db_password = root123
self_registration = on
use_compressed_js = on
max_job_workers = 3 
verify_remote_cert = on
customize_crt = on
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <h2 id="运行安装脚本"><a aria-hidden="true" tabindex="-1" href="#运行安装脚本" class="anchor"><span class="icon icon-link"></span></a>运行安装脚本</h2>
        <p>配置设置完成运行安装脚本，⚠️ 注意如果你事先部署了 nginx 需要停掉，避免端口冲突</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token function">sudo</span> ./install.sh
</span></code><input type="hidden" value="sudo ./install.sh
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>要更改 Harbour 的配置，请先停止现有的 Harbor 实例并更新 <code>harbour.cfg</code>。 然后运行 <code>prepare</code> 脚本来填充配置，最后重新创建并启动Harbor的实例：</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">docker-compose</span> down <span class="token parameter variable">-v</span>
</span><span class="code-line line-number" line="2"><span class="token comment"># 注：其实上面是停止 docker-compose.yml 中定义的所有容器</span>
</span><span class="code-line line-number" line="3">$ <span class="token function">vim</span> harbor.cfg
</span><span class="code-line line-number" line="4">$ prepare
</span><span class="code-line line-number" line="5">$ <span class="token function">docker-compose</span> up <span class="token parameter variable">-d</span>
</span></code><input type="hidden" value="$ docker-compose down -v
# 注：其实上面是停止 docker-compose.yml 中定义的所有容器
$ vim harbor.cfg
$ prepare
$ docker-compose up -d
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>通过 <a href="http://192.168.188.222">http://192.168.188.222</a> 就可以访问 Harbour 服务了</p>
        <h2 id="配置修改"><a aria-hidden="true" tabindex="-1" href="#配置修改" class="anchor"><span class="icon icon-link"></span></a>配置修改</h2>
        <p>因为 <code>harbor</code> 默认端口为 <code>80</code>，而大多数时候是不希望使用 <code>80</code> 端口的，修改端口方法如下</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token comment"># vim docker-compose.yml</span>
</span><span class="code-line line-number" line="2">
</span><span class="code-line line-number" line="3">proxy:
</span><span class="code-line line-number" line="4">  image: vmware/nginx-photon:v1.5.1
</span><span class="code-line line-number" line="5">  container_name: nginx
</span><span class="code-line line-number" line="6">  restart: always
</span><span class="code-line line-number" line="7">  volumes:
</span><span class="code-line line-number" line="8">    - ./common/config/nginx:/etc/nginx:z
</span><span class="code-line line-number" line="9">  networks:
</span><span class="code-line line-number" line="10">    - harbor
</span><span class="code-line line-number" line="11">  ports:
</span><span class="code-line line-number" line="12">    - <span class="token number">8070</span>:80
</span><span class="code-line line-number" line="13">    - <span class="token number">443</span>:443
</span></code><input type="hidden" value="# vim docker-compose.yml

proxy:
  image: vmware/nginx-photon:v1.5.1
  container_name: nginx
  restart: always
  volumes:
    - ./common/config/nginx:/etc/nginx:z
  networks:
    - harbor
  ports:
    - 8070:80
    - 443:443
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>修改 <code>common/templates/registry/config.yml</code> 文件</p>
        <pre><code class="code-highlight"><span class="code-line line-number" line="1"># vim common/templates/registry/config.yml
</span><span class="code-line line-number" line="2">auth:
</span><span class="code-line line-number" line="3">  token:
</span><span class="code-line line-number" line="4">    issuer: harbor-token-issuer
</span><span class="code-line line-number" line="5">    realm: $public_url:8070/service/token
</span><span class="code-line line-number" line="6">    rootcertbundle: /etc/registry/root.crt
</span><span class="code-line line-number" line="7">service: harbor-registry
</span></code><input type="hidden" value="# vim common/templates/registry/config.yml
auth:
  token:
    issuer: harbor-token-issuer
    realm: $public_url:8070/service/token
    rootcertbundle: /etc/registry/root.crt
service: harbor-registry
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <h2 id="使用-harbor"><a aria-hidden="true" tabindex="-1" href="#使用-harbor" class="anchor"><span class="icon icon-link"></span></a>使用 harbor</h2>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token comment"># 镜像推送</span>
</span><span class="code-line line-number" line="2"><span class="token function">docker</span> login <span class="token number">192.168</span>.188.222:8070
</span><span class="code-line line-number" line="3"><span class="token comment"># 查看 cat ~/.docker/config.json</span>
</span><span class="code-line line-number" line="4"><span class="token comment"># 镜像打包时候需要按一定规则 tag</span>
</span><span class="code-line line-number" line="5"><span class="token function">docker</span> pull nginx
</span><span class="code-line line-number" line="6"><span class="token function">docker</span> tag nginx <span class="token number">192.168</span>.188.222:8070/library/nginx:latest
</span><span class="code-line line-number" line="7"><span class="token function">docker</span> push <span class="token number">192.168</span>.188.222:8070/library/nginx
</span><span class="code-line line-number" line="8"><span class="token function">docker</span> rmi <span class="token parameter variable">-f</span> <span class="token number">192.168</span>.188.222:8070/library/nginx:latest
</span></code><input type="hidden" value="# 镜像推送
docker login 192.168.188.222:8070
# 查看 cat ~/.docker/config.json
# 镜像打包时候需要按一定规则 tag
docker pull nginx
docker tag nginx 192.168.188.222:8070/library/nginx:latest
docker push 192.168.188.222:8070/library/nginx
docker rmi -f 192.168.188.222:8070/library/nginx:latest
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>若推送镜像报以下错误:</p>
        <blockquote>
          <p>Error response from daemon: Get <a href="https://192.168.188.222:8070/v1/users/">https://192.168.188.222:8070/v1/users/</a>: http: server gave HTTP response to HTTPS client</p>
        </blockquote>
        <p>原因为，<code>docker</code> 默认使用的是 <code>https</code> 协议，而搭建的 <code>Harbor</code> 是 <code>http</code> 提供服务的，所以要配置可信任。PS：如果 <code>Harbor</code> 是 <code>https</code> 的就不会报该错误。</p>
        <p>方法1</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token comment"># vim /usr/lib/systemd/system/docker.service</span>
</span><span class="code-line line-number" line="2"><span class="token assign-left variable">ExecStart</span><span class="token operator">=</span>/usr/bin/dockerd --insecure-registry<span class="token operator">=</span><span class="token number">192.168</span>.188.222:8070
</span><span class="code-line line-number" line="3"><span class="token comment"># 修改完毕后按安装步骤走一遍即可。</span>
</span></code><input type="hidden" value="# vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --insecure-registry=192.168.188.222:8070
# 修改完毕后按安装步骤走一遍即可。
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>方法2</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token comment"># vim /etc/docker/daemon.json</span>
</span><span class="code-line line-number" line="2">
</span><span class="code-line line-number" line="3"><span class="token punctuation">{</span>
</span><span class="code-line line-number" line="4"> <span class="token string">"registry-mirrors"</span><span class="token builtin class-name">:</span> <span class="token punctuation">[</span><span class="token string">"http://xxx.m.daocloud.io"</span><span class="token punctuation">]</span>,
</span><span class="code-line line-number" line="5"> <span class="token string">"insecure-registries"</span>:<span class="token punctuation">[</span><span class="token string">"192.168.100.127:8070"</span><span class="token punctuation">]</span>
</span><span class="code-line line-number" line="6"><span class="token punctuation">}</span>
</span></code><input type="hidden" value="# vim /etc/docker/daemon.json

{
 &#x22;registry-mirrors&#x22;: [&#x22;http://xxx.m.daocloud.io&#x22;],
 &#x22;insecure-registries&#x22;:[&#x22;192.168.100.127:8070&#x22;]
}
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <pre class="language-json"><code class="language-json code-highlight"><span class="code-line line-number" line="1"><span class="token punctuation">{</span>
</span><span class="code-line line-number" line="2">  <span class="token property">"insecure-registries"</span> <span class="token operator">:</span> <span class="token punctuation">[</span>
</span><span class="code-line line-number" line="3">    <span class="token string">"docker.google.com"</span>
</span><span class="code-line line-number" line="4">  <span class="token punctuation">]</span><span class="token punctuation">,</span>
</span><span class="code-line line-number" line="5">  <span class="token property">"debug"</span> <span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
</span><span class="code-line line-number" line="6">  <span class="token property">"experimental"</span> <span class="token operator">:</span> <span class="token boolean">true</span>
</span><span class="code-line line-number" line="7"><span class="token punctuation">}</span>
</span></code><input type="hidden" value="{
  &#x22;insecure-registries&#x22; : [
    &#x22;docker.google.com&#x22;
  ],
  &#x22;debug&#x22; : true,
  &#x22;experimental&#x22; : true
}
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>客户机docker启动时候带上 <code>--insecure-registry=docker.xxx.com</code> 强制 <code>docker login</code> 走 <code>http</code> 的 <code>80</code> 端口，就可以正常 <code>push</code> 了</p>
        <div class="previous"><a class="prev" href="gitlab/index.html"><svg viewBox="0 0 1024 1024" width="16" height="16" fill="currentColor">
              <path d="M842.666667 864c-8.533333 0-14.933333-2.133333-21.333334-8.533333l-341.333333-309.333334c-6.4-6.4-10.666667-14.933333-10.666667-23.466666 0-8.533333 4.266667-17.066667 10.666667-23.466667l341.333333-309.333333c12.8-12.8 34.133333-10.666667 44.8 2.133333 12.8 12.8 10.666667 34.133333-2.133333 44.8L548.266667 522.666667l315.733333 285.866666c12.8 10.666667 14.933333 32 2.133333 44.8-6.4 6.4-14.933333 10.666667-23.466666 10.666667z"></path>
              <path d="M512 864c-8.533333 0-14.933333-2.133333-21.333333-8.533333L149.333333 546.133333c-6.4-6.4-10.666667-14.933333-10.666666-23.466666 0-8.533333 4.266667-17.066667 10.666666-23.466667L490.666667 189.866667c12.8-12.8 34.133333-10.666667 44.8 2.133333 12.8 12.8 10.666667 34.133333-2.133334 44.8L217.6 522.666667 533.333333 808.533333c12.8 12.8 14.933333 32 2.133334 44.8-6.4 6.4-14.933333 10.666667-23.466667 10.666667z"></path>
            </svg>
<span>Gitlab 代码仓库管理系统
</span></a><a class="next" href="mattermost.html"><span>Mattermost 聊天工具
</span><svg viewBox="0 0 1024 1024" width="16" height="16" fill="currentColor">
              <path d="M544 522.666667c0-8.533333-4.266667-17.066667-10.666667-23.466667L192 189.866667c-12.8-12.8-34.133333-10.666667-44.8 2.133333-12.8 12.8-10.666667 34.133333 2.133333 44.8l315.733334 285.866667L149.333333 808.533333c-12.8 12.8-14.933333 32-2.133333 44.8 6.4 6.4 14.933333 10.666667 23.466667 10.666667 8.533333 0 14.933333-2.133333 21.333333-8.533333l341.333333-309.333334c6.4-6.4 10.666667-14.933333 10.666667-23.466666z"></path>
              <path d="M864 499.2l-341.333333-309.333333c-12.8-12.8-34.133333-10.666667-44.8 2.133333-12.8 12.8-10.666667 34.133333 2.133333 44.8l315.733333 285.866667-315.733333 285.866666c-12.8 12.8-14.933333 32-2.133333 44.8 6.4 6.4 14.933333 10.666667 23.466666 10.666667 8.533333 0 14.933333-2.133333 21.333334-8.533333l341.333333-309.333334c6.4-6.4 10.666667-14.933333 10.666667-23.466666 0-8.533333-4.266667-17.066667-10.666667-23.466667z"></path>
            </svg></a></div>
        <section class="article-footer"><a href="https://github.com/jaywcjlove/docker-tutorial/tree/master/docs/harbor.md" class="edit-button" target="_blank" rel="noopener noreferrer"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
              <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
            </svg>
<span>Edit this page on GitHub</span>
</a><span class="atime">2021/10/22</span></section>
      </markdown-style>
      <nav class="tocs">
        <aside class="inner toc">
          <ol class="tocs-list">
            <li><a href="#下载安装包" class="tocs-link">下载安装包</a></li>
            <li><a href="#修改配置" class="tocs-link">修改配置</a></li>
            <li><a href="#运行安装脚本" class="tocs-link">运行安装脚本</a></li>
            <li><a href="#配置修改" class="tocs-link">配置修改</a></li>
            <li><a href="#使用-harbor" class="tocs-link">使用 harbor</a></li>
          </ol>
        </aside>
      </nav>
    </div>
    <script src="js/demo-preview.js?v=1.29.0"></script>
    <div class="footer warpper">
      <a href="https://wangchujiang.com/#/app" target="_blank">App</a> •
      <a href="https://wangchujiang.com/#/projects" target="_blank">Projects</a> •
      <a href="https://wangchujiang.com/#/sponsor" target="_blank">Sponsor</a> •
      <a href="https://wangchujiang.com/#/app" target="_blank">More Apps</a><br><br>Released under the MIT License. Copyright © 2024 <a href="https://wangchujiang.com/#/about" target="_blank">Kenny Wong</a><br>Generated by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a> v1.29.0
    </div>
    <script src="js/tocbot.js?v=1.29.0"></script>
  </body>
</html>
